package org.ddd.book.book;

import cn.hutool.core.collection.CollectionUtil;
import lombok.extern.slf4j.Slf4j;
import org.ddd.book.domain.IBaseEntity;
import org.ddd.book.domain.book.entity.BookroomEntity;
import org.ddd.book.domain.book.repository.IBookroomRepository;
import org.ddd.book.domain.factoty.RepositoryFactory;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class BookroomService {

    /**
     * 移除图书馆的所有图书室
     *
     * @param libraryId 图书馆ID
     */
    public void removeLibraryAllBookroom(Long libraryId) {
        List<BookroomEntity> entity = RepositoryFactory.get(IBookroomRepository.class).libraryBookroomList(libraryId);
        if (CollectionUtil.isEmpty(entity)) {
            log.info("the library not has bookroom,libraryId = {}", libraryId);
            return;
        }
        log.info("begin to remove bookroom libraryId = {}", libraryId);
        entity.forEach(IBaseEntity::remove);
    }

}
